package com.yidu.StockControl.controller;


import com.yidu.StockControl.entity.SecurityInventors;
import com.yidu.StockControl.service.SecurityInventorsService;
import com.yidu.Util.util.Dbutil;
import com.yidu.Util.util.TableIdUtil;
import com.yidu.Util.util.TableNameUtil;
import com.yidu.Util.util.TableTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  证券库存        证券库存            证券库存
 */
@RestController
public class SecurityInventorsController {
    @Resource
    private SecurityInventorsService securityInventorsService;
    @Autowired
    Dbutil dbutil;

    @RequestMapping("/selectSecurityInventors")
    public Map selectSecurityInventors(String securityInventorsTime,String securityPrice,int page, int limit){

        List<SecurityInventors> list = securityInventorsService.selectSecurityInventors(securityInventorsTime,securityPrice,page, limit);
        int count = securityInventorsService.selectCashInventoryCount();
        Map map =new HashMap();
        map.put("code","0");
        map.put("msg",":");
        map.put("count",count);
        map.put("data",list);
        return map;
    }

    @RequestMapping("/insertSecurityInventors")
    public int insertSecurityInventors(SecurityInventors securityInventors, HttpServletRequest request){
        System.out.println("插入插入插入插入插入插入插入插入插入插入插入插入插入");
        HttpSession session = request.getSession();
        String fundId = (String) session.getAttribute("fundId");
        String maxId3 = dbutil.getMaxId3(TableIdUtil.SSID, TableNameUtil.SIS, TableTimeUtil.SSTime, securityInventors.getSecurityInventorsTime());
        securityInventors.setSecurityInventorsId(maxId3);
        securityInventors.setFundId(fundId);
        int i =securityInventorsService.insertSecurityInventors(securityInventors);
        return i;
    }

    @RequestMapping("/updateSecurityInventors")
    public void updateSecurityInventors(SecurityInventors securityInventors){
        System.out.println("修改修改修改修改修改修改修改修改修改修改修改修改修改");
        securityInventorsService.updateSecurityInventors(securityInventors);
    }

    @RequestMapping("/deleteSecurityInventors")
    public void deleteSecurityInventors(String securityInventorsId){
        System.out.println("删除删除删除删除删除删除删除删除删除删除删除删除");
        System.out.println(securityInventorsId);
        securityInventorsService.deleteSecurityInventors(securityInventorsId);
    }
}
